package com.bite.demo.mapper;

import com.bite.demo.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BlogInfoMapper {

    //查询所有博客
    @Select("select id,title,content,user_id,delete_flag,update_time from `blog` where delete_flag = 0 order by id desc")
    List<BlogInfo> selectAll();

    //根据博客id，查询博客信息
    @Select("select id,title,content,user_id,delete_flag,update_time from `blog` where delete_flag = 0 and id = #{id} ")
    BlogInfo selectById(Integer id);

    //插入博客
    @Insert("insert into `blog` (title,content,user_id) values(#{title},#{content},#{userId}) " )
    Integer insertBlog(BlogInfo blogInfo);

    //更新博客
    Integer updateBlog(BlogInfo blogInfo);

    //
    @Select("select id,title,content,user_id,delete_flag,update_time from `blog` where delete_flag = 0 order by id desc LIMIT #{offset},#{limit}")
    List<BlogInfo> selectAllByPage(Integer offset,Integer limit);

    @Select("select count(1) from `blog` where delete_flag = 0  ")
    Integer count();

}
